package cn.itlaobing.web;

import cn.itlaobing.annotation.RequestMapping;
import cn.itlaobing.entity.QueryInfo;
import cn.itlaobing.service.QueryInfoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * Created by Berlin-IOU on 2017/11/9.
 */
@WebServlet("/train/*")
public class QueryPriceServlet extends BaseServlet {
    private QueryInfoService queryInfoService=new QueryInfoService();
    @RequestMapping("/findtrain")
    public void findtrain(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        String trainnum=request.getParameter("trainnum");
        String startaddress=request.getParameter("startaddress");
        String endaddress=request.getParameter("endaddress");
        QueryInfo queryInfo=queryInfoService.findPrice(trainnum,startaddress,endaddress);
        if(queryInfo==null){
            request.setAttribute("ERROR","查不到信息！");
            request.getRequestDispatcher(request.getContextPath()+"/WEB-INF/views/error.jsp").forward(request,response);
            return;
        }
        request.setAttribute("TRAININFO",queryInfo);
        request.getRequestDispatcher(request.getContextPath()+"/WEB-INF/views/traininfo.jsp").forward(request,response);
        return;
    }
}
